package com.chiwen.web.controller.ks;

import com.chiwen.common.annotation.Log;
import com.chiwen.common.core.controller.BaseController;
import com.chiwen.common.core.domain.AjaxResult;
import com.chiwen.common.core.domain.entity.SysUser;
import com.chiwen.common.core.page.TableDataInfo;
import com.chiwen.common.enums.BusinessType;
import com.chiwen.common.utils.SecurityUtils;
import com.chiwen.common.utils.poi.ExcelUtil;
import com.chiwen.ks.domain.KsUser;
import com.chiwen.ks.service.IKsUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 快手用户管理Controller
 * 
 * @author dipper
 * @date 2022-12-08
 */
@RestController
@RequestMapping("/ks/ksUser")
public class KsUserController extends BaseController
{
    @Autowired
    private IKsUserService ksUserService;

    /**
     * 查询快手用户管理列表
     */
    @PreAuthorize("@ss.hasPermi('ks:ksUser:list')")
    @GetMapping("/list")
    public TableDataInfo list(KsUser ksUser)
    {
        startPage();
        List<KsUser> list = ksUserService.selectKsUserList(ksUser);
        return getDataTable(list);
    }

    /**
     * 导出快手用户管理列表
     */
    @PreAuthorize("@ss.hasPermi('ks:ksUser:export')")
    @Log(title = "快手用户管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KsUser ksUser)
    {
        List<KsUser> list = ksUserService.selectKsUserList(ksUser);
        ExcelUtil<KsUser> util = new ExcelUtil<KsUser>(KsUser.class);
        util.exportExcel(response, list, "快手用户管理数据");
    }

    /**
     * 获取快手用户管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('ks:ksUser:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Integer userId)
    {
        return success(ksUserService.selectKsUserByUserId(userId));
    }

    /**
     * 新增快手用户管理
     */
    @PreAuthorize("@ss.hasPermi('ks:ksUser:add')")
    @Log(title = "快手用户管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KsUser ksUser)
    {
        SysUser user = SecurityUtils.getLoginUser().getUser();
        ksUser.setDeptId(user.getDeptId());
        ksUser.setCreateBy(String.valueOf(user.getUserId()));
        return toAjax(ksUserService.insertKsUser(ksUser));
    }

    /**
     * 修改快手用户管理
     */
    @PreAuthorize("@ss.hasPermi('ks:ksUser:edit')")
    @Log(title = "快手用户管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KsUser ksUser)
    {
        return toAjax(ksUserService.updateKsUser(ksUser));
    }

    /**
     * 删除快手用户管理
     */
    @PreAuthorize("@ss.hasPermi('ks:ksUser:remove')")
    @Log(title = "快手用户管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Integer[] userIds)
    {
        return toAjax(ksUserService.deleteKsUserByUserIds(userIds));
    }
}
